package com.example.allshengmedical.experimentnew.activity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Environment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.LayoutManager;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import android.widget.TextView;

import com.example.allshengmedical.R;
import com.example.allshengmedical.base.BaseActivity;
import com.example.allshengmedical.base.BaseApplication;
import com.example.allshengmedical.experimentnew.bean.LayoutTableBean;
import com.example.allshengmedical.experimentnew.bean.MethodBean;
import com.example.allshengmedical.experimentnew.presenter.PreviewPresenter;
import com.example.allshengmedical.experimentnew.view.IPreviewView;
import com.example.allshengmedical.mainmenu.activity.MainMenuActivity;
import com.example.allshengmedical.util.ByAlert;
import com.example.allshengmedical.util.DragGridView;
import com.example.allshengmedical.util.FileManagerUtil;
import com.example.allshengmedical.util.ListViewForScrollView;
import com.example.allshengmedical.util.MyHorizontalScrollView;
import com.example.allshengmedical.util.ScrollViewListener;
import com.example.allshengmedical.util.SharedPreferencesUtils;
import com.example.allshengmedical.util.SimpleLineChart;

//预览界面
public class PreviewActivity extends BaseActivity implements IPreviewView,
		OnClickListener, ScrollViewListener {

	private TextView experimentNameET, experimentIdEt, experimenterEt,
			spinnerExperType, spinnerSampleType, spinnerReagent;

	private PreviewPresenter previewPresenter;
	// menu的配置
	private boolean menuboo;
	private PopupWindow menuPopupWindow;

	// LayoutOne信息的配置
	private ListViewForScrollView standardInfoLv;
	private StandardListViewAdapter standardListViewAdapter;
	private ArrayList<LayoutTableBean> activityLayoutTableBeans;

	// 基因盘
	private DragGridView dragGridView1, dragGridView2;
	private DragGridViewAdapter dragGridViewAdapter;

	// private RecyclerViewAdapter recyclerViewAdapter;

	FileManagerUtil fileManagerUtil;

	// 曲线图
	// 上半部
	private RecyclerView steptRv;
	private RecyclerViewAdapter recyclerViewAdapter;
	private ArrayList<MethodBean> activityMethodBeans;

	// 下半部分
	private SimpleLineChart mSimpleLineChart;

	// 下面的图表
	HashMap<Integer, Integer> pointMap = new HashMap();
	List<HashMap<String, Object>> pointMaps = new ArrayList<HashMap<String, Object>>();

	private String[] xItem, yItem = { "", "", "", "", "", "", "", "", "", "",
			"" };

	// 下面的横划
	MyHorizontalScrollView downScrollView, upScrollView;

	@Override
	protected int setcontent() {
		return R.layout.activity_new_preview;
	}

	@Override
	protected void initView() {

		fileManagerUtil = new FileManagerUtil();

		// aRecyclerView = BindView(R.id.aRecyclerView);steptRv
		// bRecyclerView = BindView(R.id.bRecyclerView);
		downScrollView = BindView(R.id.downScrollView);
		downScrollView.setScrollViewListener(this);
		upScrollView = BindView(R.id.upScrollView);
		upScrollView.setScrollViewListener(this);

		previewPresenter = new PreviewPresenter(this);
		previewPresenter.initAppHead();
		previewPresenter.initBottomView();

		previewPresenter.initBaseInformation();
		previewPresenter.initLayoutOne();
		previewPresenter.initGene();
		previewPresenter.initSimpleLineChart();

		dragGridView1.isDrag = false;
		dragGridView2.isDrag = false;

	}

	@Override
	protected void initData() {

	}

	@Override
	public void onClick(View v) {

		// TODO Auto-generated method stub

	}

	@Override
	public void initAppHead() {
		setActionBar();
		setSystemTime();

	}

	@Override
	public void initBottomView() {
		setBottomView();

	}

	@Override
	public void getInfo() {
		// BaseInformationActivity.getInstence()

	}

	@Override
	public void initBaseInformation() {

		String appFilePath = Environment.getExternalStorageDirectory()
				+ "/"
				+ "AllShengMedical"
				+ "/"
				+ SharedPreferencesUtils.get(this,
						BaseApplication.FILEMANGER_PREPAREFOLDERPATH, "0")
				+ "/"
				+ SharedPreferencesUtils.get(this,
						BaseApplication.FILEMANGER_PREPAREFILENAME, "0");
		Log.e("!!!", appFilePath);
		fileManagerUtil
				.readFileByLines(
						SharedPreferencesUtils.get(this,
								BaseApplication.FILEMANGER_PREPAREFOLDERPATH,
								"0")
								+ "",
						SharedPreferencesUtils
								.get(this,
										BaseApplication.FILEMANGER_PREPAREFILENAME,
										"0")
								+ "");

		experimentNameET
				.setText(BaseInformationActivity.getInstence().experimentNameET
						.getText().toString());
		experimentIdEt
				.setText(BaseInformationActivity.getInstence().experimentIdEt
						.getText().toString());
		experimenterEt
				.setText(BaseInformationActivity.getInstence().experimenterEt
						.getText().toString());

		// TODO:由于基本信息页面修改之后，导致预览界面也有对应的改动。

		spinnerExperType
				.setText(BaseInformationActivity.getInstence().spinnerExperTypeData_list
						.get(BaseInformationActivity.getInstence().spinnerExperType
								.getSelectedItemPosition()).toString());
		spinnerSampleType
				.setText(BaseInformationActivity.getInstence().spinnerSampleTypeData_list
						.get(BaseInformationActivity.getInstence().spinnerSampleType
								.getSelectedItemPosition()).toString());
		spinnerReagent
				.setText(BaseInformationActivity.getInstence().spinnerReagentData_list
						.get(BaseInformationActivity.getInstence().spinnerReagent
								.getSelectedItemPosition()).toString());

	}

	@Override
	public void initLayoutOne() {
		initListView();

	}

	@Override
	public void initGene() {
		initGeneView();

	}

	@Override
	public void initSimpleLineChart() {
		initSimpleLineChartView();

	}

	// 设置actionBar
	public void setActionBar() {
		Button leftfirstBtn, leftsecondBtn, rightfirstBtn, rightsecondBtn, rightthirdBtn;
		TextView title;

		leftfirstBtn = BindView(R.id.leftfirst_btn);
		leftsecondBtn = BindView(R.id.leftsecond_btn);

		title = BindView(R.id.title);

		leftfirstBtn.setVisibility(View.VISIBLE);
		leftfirstBtn.setText(R.string.item_actionbar_menu);
		leftsecondBtn.setVisibility(View.VISIBLE);
		leftsecondBtn.setText(R.string.item_actionbar_home);

		title.setText("PreView");

		leftfirstBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (!menuboo) {
					showMenuPopupWindow(v);
					menuboo = !menuboo;
				} else {
					menuPopupWindow.dismiss();
					menuboo = !menuboo;
				}

			}

		});

		leftsecondBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(PreviewActivity.this,
						MainMenuActivity.class);
				startActivity(intent);
				finish();
			}
		});

	}

	// 获取当前时间的方法
	public void setSystemTime() {

		TextView date, fileName;
		date = BindView(R.id.date);
		fileName = BindView(R.id.file_name);

		// 获取系统时间
		SimpleDateFormat sdfDate = new SimpleDateFormat("MM dd,yyyy");
		date.setText(sdfDate.format(new Date()));

		// 文件路径置空
		fileName.setText("");

	}

	// 弹出的跳转菜单
	private void showMenuPopupWindow(View v) {
		if (null == menuPopupWindow || !menuPopupWindow.isShowing()) {
			View contentView = LayoutInflater.from(this).inflate(
					R.layout.fragment_new_basicinformation_menu, null);

			menuPopupWindow = new PopupWindow(contentView,
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			menuPopupWindow.setBackgroundDrawable(new BitmapDrawable());
			menuPopupWindow.setTouchable(true);
			menuPopupWindow.setOutsideTouchable(true);
			menuPopupWindow.showAsDropDown(v, -40, -3);

			TextView basicInformationTv, layoutTv, methodTv, previewTv;
			basicInformationTv = (TextView) contentView
					.findViewById(R.id.basicInformationTv);
			layoutTv = (TextView) contentView.findViewById(R.id.layoutTv);
			methodTv = (TextView) contentView.findViewById(R.id.methodTv);
			previewTv = (TextView) contentView.findViewById(R.id.previewTv);

			basicInformationTv.setBackground(getResources().getDrawable(
					R.color.darkBlue));
			basicInformationTv.setTextColor(this.getResources().getColor(
					R.color.white));
			layoutTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面layout");

				}
			});
			methodTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面method");
				}
			});
			previewTv.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					ByAlert.alert("跳转页面preview");
				}
			});

		} else {
			menuPopupWindow.dismiss();
			menuboo = !menuboo;
		}

	}

	private void setBottomView() {
		Button bottomLeftFistBtn, bottomCenterBtn, bottomRightBtn;

		bottomLeftFistBtn = BindView(R.id.bottomLeftFistBtn);
		bottomCenterBtn = BindView(R.id.bottomCenterBtn);
		bottomRightBtn = BindView(R.id.bottomRightBtn);

		bottomLeftFistBtn.setVisibility(View.VISIBLE);
//		bottomCenterBtn.setVisibility(View.VISIBLE);
		bottomRightBtn.setVisibility(View.VISIBLE);

		bottomLeftFistBtn.setText(R.string.bottomView_back);
		// TODO 这个button的文字不确定暂时用A代替
		bottomCenterBtn.setText("A"); // 不确定！！！！！！！
		bottomRightBtn.setText(R.string.bottomView_next);

		bottomLeftFistBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// ByAlert.alert("back");
				finish();

			}
		});

		bottomCenterBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("A");

			}
		});
		bottomRightBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				ByAlert.alert("next");
			}
		});

	}

	public class StandardListViewAdapter extends BaseAdapter {
		private ArrayList<LayoutTableBean> layoutTableBeans;

		public StandardListViewAdapter(
				ArrayList<LayoutTableBean> layoutTableBeans) {
			super();
			this.layoutTableBeans = layoutTableBeans;
		}

		public void removeBean(Object layoutTableBean) {
			layoutTableBeans.remove(layoutTableBean);
			activityLayoutTableBeans.remove(layoutTableBean);
			notifyDataSetChanged();

		}

		class ViewHolder {
			TextView numTv, targetTv, aisleTv;
			CheckBox checkBox;
			ImageView colorIv;
			TextView fluorescentSpinner;
		}

		@Override
		public int getCount() {
			return layoutTableBeans != null ? layoutTableBeans.size() : 0;
		}

		@Override
		public Object getItem(int position) {
			return layoutTableBeans != null ? layoutTableBeans.get(position)
					: null;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			final ViewHolder holder;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = LayoutInflater.from(PreviewActivity.this)
						.inflate(R.layout.item_listview_preview_standard, null);
				holder.aisleTv = (TextView) convertView
						.findViewById(R.id.aisleTv);
				holder.checkBox = (CheckBox) convertView
						.findViewById(R.id.checkBox);
				holder.colorIv = (ImageView) convertView
						.findViewById(R.id.colorIv);
				holder.fluorescentSpinner = (TextView) convertView
						.findViewById(R.id.fluorescentSpinner);
				holder.numTv = (TextView) convertView.findViewById(R.id.numTv);
				holder.targetTv = (TextView) convertView
						.findViewById(R.id.targetTv);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}

			if (layoutTableBeans.get(position).getChoseen()) {
				holder.checkBox.setChecked(true);
			}
			if (activityLayoutTableBeans.get(position).getColor() == 0) {
				holder.colorIv.setBackground(getResources().getDrawable(
						R.color.white));
			} else {
				switch (activityLayoutTableBeans.get(position).getColor()) {
				case 11:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_one));
					break;
				case 12:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_two));
					break;
				case 13:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_three));

					break;
				case 14:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_four));

					break;
				case 15:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_five));

					break;
				case 16:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_one_six));

					break;
				case 21:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_one));
					break;
				case 22:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_two));
					break;
				case 23:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_three));
					break;
				case 24:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_four));
					break;
				case 25:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_five));
					break;
				case 26:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_two_six));
					break;
				case 31:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_one));
					break;
				case 32:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_two));
					break;
				case 33:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_three));
					break;
				case 34:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_four));
					break;
				case 35:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_five));
					break;
				case 36:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_three_six));
					break;

				case 41:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_one));
					break;
				case 42:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_two));
					break;
				case 43:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_three));
					break;
				case 44:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_four));
					break;
				case 45:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_five));
					break;
				case 46:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_four_six));
					break;
				case 51:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_one));
					break;
				case 52:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_two));
					break;
				case 53:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_three));
					break;
				case 54:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_four));
					break;
				case 55:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_five));
					break;
				case 56:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_five_six));
					break;
				case 61:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_one));
					break;
				case 62:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_two));

					break;
				case 63:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_three));
					break;
				case 64:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_four));
					break;
				case 65:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_five));
					break;
				case 66:
					holder.colorIv.setBackground(getResources().getDrawable(
							R.color.palette_six_six));
					break;
				default:
					break;
				}
			}

			holder.numTv.setText(position + 1 + "");

			holder.fluorescentSpinner.setText(layoutTableBeans.get(position)
					.getFluorescentDyes() + "");
			if ("1".equals(layoutTableBeans.get(position).getAisle())) {
				holder.aisleTv.setText("1:470/525nm");
			} else if ("2".equals(layoutTableBeans.get(position).getAisle())) {
				holder.aisleTv.setText("2:530/571nm");
			} else if ("3".equals(layoutTableBeans.get(position).getAisle())) {
				holder.aisleTv.setText("3:571/612nm");
			} else if ("4".equals(layoutTableBeans.get(position).getAisle())) {
				holder.aisleTv.setText("4:620/680nm");
			}

			holder.targetTv.setText(layoutTableBeans.get(position).getTarget());

			holder.checkBox.setVisibility(View.GONE);

			return convertView;
		}
	}

	private void initListView() {

		activityLayoutTableBeans = new ArrayList<LayoutTableBean>();

		activityLayoutTableBeans
				.addAll(LayoutOneActivity.getInstence().activityLayoutTableBeans);
		standardListViewAdapter = new StandardListViewAdapter(
				activityLayoutTableBeans);
		standardInfoLv.setAdapter(standardListViewAdapter);
	}

	private void initGeneView() {

		if ("Absolute Quantitation".equals(SharedPreferencesUtils.get(
				PreviewActivity.this,
				BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))
				| "绝对定量".equals(SharedPreferencesUtils.get(
						PreviewActivity.this,
						BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))) {

			dragGridViewAdapter = new DragGridViewAdapter(
					AbsoluteQuaLayoutActivity.getInstence().dataSourceListBlock1);

			dragGridView1.setAdapter(dragGridViewAdapter);

			dragGridViewAdapter = new DragGridViewAdapter(
					AbsoluteQuaLayoutActivity.getInstence().dataSourceListBlock2);
			dragGridView2.setAdapter(dragGridViewAdapter);

			ByAlert.alert("跳转绝对定量的页面");
		} else if ("Standard Curve Relative Quantitation"
				.equals(SharedPreferencesUtils.get(PreviewActivity.this,
						BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))
				| "标准曲线相对定量".equals(SharedPreferencesUtils.get(
						PreviewActivity.this,
						BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))) {

			dragGridViewAdapter = new DragGridViewAdapter(
					StandardCurveLayoutActivity.getInstence().dataSourceListBlock1);

			dragGridView1.setAdapter(dragGridViewAdapter);

			dragGridViewAdapter = new DragGridViewAdapter(
					StandardCurveLayoutActivity.getInstence().dataSourceListBlock2);
			dragGridView2.setAdapter(dragGridViewAdapter);

			ByAlert.alert("跳转标准曲线的页面");
		} else if ("⊿Ct Relative Quantitation".equals(SharedPreferencesUtils
				.get(PreviewActivity.this,
						BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))
				| "比较ct值相对定量".equals(SharedPreferencesUtils.get(
						PreviewActivity.this,
						BaseApplication.BASEINFORMATION_EXPERIMENTTYPE, ""))) {

			dragGridViewAdapter = new DragGridViewAdapter(
					CompareCtLayoutActivity.getInstence().dataSourceListBlock1);

			dragGridView1.setAdapter(dragGridViewAdapter);

			dragGridViewAdapter = new DragGridViewAdapter(
					CompareCtLayoutActivity.getInstence().dataSourceListBlock2);
			dragGridView2.setAdapter(dragGridViewAdapter);
			ByAlert.alert("跳转比较ct值页面");
		} else {
			ByAlert.alert("实验类型不匹配！");
		}

		// dragGridViewAdapter= new DragGridViewAdapter(dataSourceListBlock);
		//
		// aRecyclerView

	}

	// class RecyclerViewAdapter extends
	// RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {
	//
	// List<HashMap<String, Object>> dataSourceListBlock = new
	// ArrayList<HashMap<String, Object>>();
	//
	// public RecyclerViewAdapter(
	// List<HashMap<String, Object>> dataSourceListBlock) {
	// super();
	// this.dataSourceListBlock = dataSourceListBlock;
	// }
	//
	// class MyViewHolder extends ViewHolder {
	//
	// LinearLayout line, textViewLine;
	// ImageView item_image;
	// TextView item_text, aisle1, aisle2, aisle3, aisle4;
	//
	// public MyViewHolder(View view) {
	// super(view);
	// line = (LinearLayout) view.findViewById(R.id.line);
	// textViewLine = (LinearLayout) view
	// .findViewById(R.id.textViewLine);
	// item_image = (ImageView) view.findViewById(R.id.item_image);
	// item_text = (TextView) view.findViewById(R.id.item_text);
	// aisle1 = (TextView) view.findViewById(R.id.aisle1);
	// aisle2 = (TextView) view.findViewById(R.id.aisle2);
	// aisle3 = (TextView) view.findViewById(R.id.aisle3);
	// aisle4 = (TextView) view.findViewById(R.id.aisle4);
	// }
	// }
	//
	// @Override
	// public int getItemCount() {
	// return dataSourceListBlock != null ? dataSourceListBlock.size() : 0;
	// }
	//
	// @Override
	// public void onBindViewHolder(MyViewHolder holder, int position) {
	// holder.aisle1.setVisibility(View.INVISIBLE);
	// holder.aisle2.setVisibility(View.INVISIBLE);
	// holder.aisle3.setVisibility(View.INVISIBLE);
	// holder.aisle4.setVisibility(View.INVISIBLE);
	// holder.textViewLine.setVisibility(View.INVISIBLE);
	// holder.item_image.setBackground(getResources().getDrawable(
	// R.color.white));
	//
	// if (dataSourceListBlock.get(position).get("item_null") != null) {
	// if ((Boolean) dataSourceListBlock.get(position)
	// .get("item_null")) {
	// holder.aisle1.setVisibility(View.INVISIBLE);
	// holder.aisle2.setVisibility(View.INVISIBLE);
	// holder.aisle3.setVisibility(View.INVISIBLE);
	// holder.aisle4.setVisibility(View.INVISIBLE);
	// holder.textViewLine.setVisibility(View.INVISIBLE);
	// holder.item_image.setBackground(getResources().getDrawable(
	// R.color.white));
	// }
	// }
	//
	// if (dataSourceListBlock.get(position).get("item_aisle") != null) {
	// if (!TextUtils.isEmpty(dataSourceListBlock.get(position).get(
	// "item_aisle")
	// + "")) {
	// int aisleNum = (Integer) dataSourceListBlock.get(position)
	// .get("item_aisle");
	// holder.textViewLine.setVisibility(View.VISIBLE);
	// holder.aisle1.setVisibility(View.VISIBLE);
	// holder.aisle2.setVisibility(View.VISIBLE);
	// holder.aisle3.setVisibility(View.VISIBLE);
	// holder.aisle4.setVisibility(View.VISIBLE);
	// switch (aisleNum) {
	// case 1:
	// setcolor(holder.aisle1, position, holder.textViewLine);
	// holder.aisle2.setBackground(getResources().getDrawable(
	// R.color.white));
	// holder.aisle3.setBackground(getResources().getDrawable(
	// R.color.white));
	// holder.aisle4.setBackground(getResources().getDrawable(
	// R.color.white));
	//
	// break;
	// case 2:
	// holder.aisle1.setBackground(getResources().getDrawable(
	// R.color.white));
	// setcolor(holder.aisle2, position, holder.textViewLine);
	// holder.aisle3.setBackground(getResources().getDrawable(
	// R.color.white));
	// holder.aisle4.setBackground(getResources().getDrawable(
	// R.color.white));
	//
	// break;
	//
	// case 3:
	// holder.aisle1.setBackground(getResources().getDrawable(
	// R.color.white));
	// holder.aisle2.setBackground(getResources().getDrawable(
	// R.color.white));
	// setcolor(holder.aisle3, position, holder.textViewLine);
	// holder.aisle4.setBackground(getResources().getDrawable(
	// R.color.white));
	// break;
	//
	// case 4:
	// holder.aisle1.setBackground(getResources().getDrawable(
	// R.color.white));
	// holder.aisle2.setBackground(getResources().getDrawable(
	// R.color.white));
	// holder.aisle3.setBackground(getResources().getDrawable(
	// R.color.white));
	// setcolor(holder.aisle4, position, holder.textViewLine);
	// break;
	//
	// default:
	// break;
	// }
	//
	// } else {
	// holder.textViewLine.setVisibility(View.INVISIBLE);
	// holder.aisle1.setVisibility(View.INVISIBLE);
	// holder.aisle2.setVisibility(View.INVISIBLE);
	// holder.aisle3.setVisibility(View.INVISIBLE);
	// holder.aisle4.setVisibility(View.INVISIBLE);
	// }
	// }
	// if ((Boolean) dataSourceListBlock.get(position)
	// .get("item_selected")) {
	// holder.line.setBackground(getResources().getDrawable(
	// R.color.darkBlue));
	// } else {
	// holder.line.setBackground(getResources().getDrawable(
	// R.color.white));
	// }
	//
	// // map.put("item_type", "positive");
	//
	// if ("sample".equals(dataSourceListBlock.get(position).get(
	// "item_type"))) {
	// holder.item_image.setBackgroundColor(Color
	// .parseColor("#ff2d55"));
	// } else if ("standard".equals(dataSourceListBlock.get(position).get(
	// "item_type"))) {
	// holder.item_image.setBackgroundColor(Color
	// .parseColor("#fd9727"));
	// } else if ("positive".equals(dataSourceListBlock.get(position).get(
	// "item_type"))) {
	// holder.item_image.setBackgroundColor(Color
	// .parseColor("#ff00a9"));
	// } else if ("negative".equals(dataSourceListBlock.get(position).get(
	// "item_type"))) {
	// holder.item_image.setBackgroundColor(Color
	// .parseColor("#159588"));
	// } else if (dataSourceListBlock.get(position).get("item_image") == null) {
	// holder.item_image.setBackground(getResources().getDrawable(
	// R.color.white));
	// } else if ("".equals(dataSourceListBlock.get(position).get(
	// "item_type"))) {
	// holder.item_image.setBackground(getResources().getDrawable(
	// R.color.white));
	// } else {
	// holder.item_image.setBackground(getResources().getDrawable(
	// R.color.white));
	// }
	// holder.item_text.setText(dataSourceListBlock.get(position).get(
	// "item_text")
	// + "");
	// }
	//
	// @Override
	// public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
	// MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
	// PreviewActivity.this).inflate(R.layout.item_layout2_grid,
	// parent, false));
	// return holder;
	// }
	//
	// private void setcolor(TextView aisle, int position,
	// LinearLayout textViewLine) {
	// if ("".equals(dataSourceListBlock.get(position).get("item_image"))) {
	// aisle.setBackground(getResources().getDrawable(R.color.white));
	// textViewLine.setVisibility(View.INVISIBLE);
	// } else if ("11".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_one_one));
	// } else if ("12".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_one_two));
	// } else if ("13".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_one_three));
	// } else if ("14".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_one_four));
	// } else if ("15".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_one_five));
	// } else if ("16".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_one_six));
	// } else if ("21".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_two_one));
	// } else if ("22".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_two_two));
	// } else if ("23".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_two_three));
	// } else if ("24".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_two_four));
	// } else if ("25".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_two_five));
	// } else if ("26".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_two_six));
	// } else if ("31".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_three_one));
	// } else if ("32".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_three_two));
	// } else if ("33".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_three_three));
	// } else if ("34".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_three_four));
	// } else if ("35".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_three_five));
	// } else if ("36".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_three_six));
	// } else if ("41".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_four_one));
	// } else if ("42".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_four_two));
	// } else if ("43".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_four_three));
	// } else if ("44".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_four_four));
	// } else if ("45".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_four_five));
	// } else if ("46".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_four_six));
	// } else if ("51".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_five_one));
	// } else if ("52".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_five_two));
	// } else if ("53".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_five_three));
	// } else if ("54".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_five_four));
	// } else if ("55".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_five_five));
	// } else if ("56".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_five_six));
	// } else if ("61".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_six_one));
	// } else if ("62".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_six_two));
	// } else if ("63".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_six_three));
	// } else if ("64".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_six_four));
	// } else if ("65".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_six_five));
	// } else if ("66".equals(dataSourceListBlock.get(position).get(
	// "item_image"))) {
	// aisle.setBackground(getResources().getDrawable(
	// R.color.palette_six_six));
	// } else if (dataSourceListBlock.get(position).get("item_image") == null) {
	// aisle.setBackground(getResources().getDrawable(R.color.white));
	// textViewLine.setVisibility(View.INVISIBLE);
	//
	// } else {
	// aisle.setBackground(getResources().getDrawable(R.color.white));
	// textViewLine.setVisibility(View.INVISIBLE);
	// }
	//
	// }
	// }

	public class DragGridViewAdapter extends BaseAdapter {
		List<HashMap<String, Object>> dataSourceListBlock = new ArrayList<HashMap<String, Object>>();

		public DragGridViewAdapter(
				List<HashMap<String, Object>> dataSourceListBlock) {
			super();
			this.dataSourceListBlock = dataSourceListBlock;
		}

		public void changeList(List<HashMap<String, Object>> dataSourceListBlock) {

			this.dataSourceListBlock = dataSourceListBlock;
			notifyDataSetChanged();
		}

		class ViewHolder {

			LinearLayout line, textViewLine;
			ImageView item_image;
			TextView item_text, aisle1, aisle2, aisle3, aisle4;

		}

		@Override
		public int getCount() {
			return dataSourceListBlock != null ? dataSourceListBlock.size() : 0;
		}

		@Override
		public Object getItem(int position) {
			return dataSourceListBlock != null ? dataSourceListBlock
					.get(position) : null;
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			final ViewHolder holder;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = LayoutInflater.from(PreviewActivity.this)
						.inflate(R.layout.item_layout2_grid, null);

				holder.line = (LinearLayout) convertView
						.findViewById(R.id.line);
				holder.item_image = (ImageView) convertView
						.findViewById(R.id.item_image);
				holder.item_text = (TextView) convertView
						.findViewById(R.id.item_text);
				holder.aisle1 = (TextView) convertView
						.findViewById(R.id.aisle1);
				holder.aisle2 = (TextView) convertView
						.findViewById(R.id.aisle2);
				holder.aisle3 = (TextView) convertView
						.findViewById(R.id.aisle3);
				holder.aisle4 = (TextView) convertView
						.findViewById(R.id.aisle4);
				holder.textViewLine = (LinearLayout) convertView
						.findViewById(R.id.textViewLine);

				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.aisle1.setVisibility(View.INVISIBLE);
			holder.aisle2.setVisibility(View.INVISIBLE);
			holder.aisle3.setVisibility(View.INVISIBLE);
			holder.aisle4.setVisibility(View.INVISIBLE);
			holder.textViewLine.setVisibility(View.INVISIBLE);
			holder.item_image.setBackground(getResources().getDrawable(
					R.color.white));

			if (dataSourceListBlock.get(position).get("item_null") != null) {
				if ((Boolean) dataSourceListBlock.get(position)
						.get("item_null")) {
					holder.aisle1.setVisibility(View.INVISIBLE);
					holder.aisle2.setVisibility(View.INVISIBLE);
					holder.aisle3.setVisibility(View.INVISIBLE);
					holder.aisle4.setVisibility(View.INVISIBLE);
					holder.textViewLine.setVisibility(View.INVISIBLE);
					holder.item_image.setBackground(getResources().getDrawable(
							R.color.white));
				}
			}

			if (dataSourceListBlock.get(position).get("item_aisle") != null) {
				if (!TextUtils.isEmpty(dataSourceListBlock.get(position).get(
						"item_aisle")
						+ "")) {
					int aisleNum = (Integer) dataSourceListBlock.get(position)
							.get("item_aisle");
					holder.textViewLine.setVisibility(View.VISIBLE);
					holder.aisle1.setVisibility(View.VISIBLE);
					holder.aisle2.setVisibility(View.VISIBLE);
					holder.aisle3.setVisibility(View.VISIBLE);
					holder.aisle4.setVisibility(View.VISIBLE);
					switch (aisleNum) {
					case 1:
						setcolor(holder.aisle1, position, holder.textViewLine);
						holder.aisle2.setBackground(getResources().getDrawable(
								R.color.white));
						holder.aisle3.setBackground(getResources().getDrawable(
								R.color.white));
						holder.aisle4.setBackground(getResources().getDrawable(
								R.color.white));

						break;
					case 2:
						holder.aisle1.setBackground(getResources().getDrawable(
								R.color.white));
						setcolor(holder.aisle2, position, holder.textViewLine);
						holder.aisle3.setBackground(getResources().getDrawable(
								R.color.white));
						holder.aisle4.setBackground(getResources().getDrawable(
								R.color.white));

						break;

					case 3:
						holder.aisle1.setBackground(getResources().getDrawable(
								R.color.white));
						holder.aisle2.setBackground(getResources().getDrawable(
								R.color.white));
						setcolor(holder.aisle3, position, holder.textViewLine);
						holder.aisle4.setBackground(getResources().getDrawable(
								R.color.white));
						break;

					case 4:
						holder.aisle1.setBackground(getResources().getDrawable(
								R.color.white));
						holder.aisle2.setBackground(getResources().getDrawable(
								R.color.white));
						holder.aisle3.setBackground(getResources().getDrawable(
								R.color.white));
						setcolor(holder.aisle4, position, holder.textViewLine);
						break;

					default:
						break;
					}

				} else {
					holder.textViewLine.setVisibility(View.INVISIBLE);
					holder.aisle1.setVisibility(View.INVISIBLE);
					holder.aisle2.setVisibility(View.INVISIBLE);
					holder.aisle3.setVisibility(View.INVISIBLE);
					holder.aisle4.setVisibility(View.INVISIBLE);
				}
			}

			// 选中的背景色设置
			// if ((Boolean) dataSourceListBlock.get(position)
			// .get("item_selected")) {
			// holder.line.setBackground(getResources().getDrawable(
			// R.color.darkBlue));
			// } else {
			// holder.line.setBackground(getResources().getDrawable(
			// R.color.white));
			// }

			// map.put("item_type", "positive");

			if ("sample".equals(dataSourceListBlock.get(position).get(
					"item_type"))) {
				holder.item_image.setBackgroundColor(Color
						.parseColor("#ff2d55"));
			} else if ("standard".equals(dataSourceListBlock.get(position).get(
					"item_type"))) {
				holder.item_image.setBackgroundColor(Color
						.parseColor("#fd9727"));
			} else if ("positive".equals(dataSourceListBlock.get(position).get(
					"item_type"))) {
				holder.item_image.setBackgroundColor(Color
						.parseColor("#ff00a9"));
			} else if ("negative".equals(dataSourceListBlock.get(position).get(
					"item_type"))) {
				holder.item_image.setBackgroundColor(Color
						.parseColor("#159588"));
			} else if (dataSourceListBlock.get(position).get("item_image") == null) {
				holder.item_image.setBackground(getResources().getDrawable(
						R.color.white));
			} else if ("".equals(dataSourceListBlock.get(position).get(
					"item_type"))) {
				holder.item_image.setBackground(getResources().getDrawable(
						R.color.white));
			} else {
				holder.item_image.setBackground(getResources().getDrawable(
						R.color.white));
			}

			// if
			// ("".equals(dataSourceListBlock.get(position).get("item_image")))
			// {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.white));
			// } else if ("11".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_one));
			// } else if ("12".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_two));
			// } else if ("13".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_three));
			// } else if ("14".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_four));
			// } else if ("15".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_five));
			// } else if ("16".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_one_six));
			// } else if ("21".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_one));
			// } else if ("22".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_two));
			// } else if ("23".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_three));
			// } else if ("24".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_four));
			// } else if ("25".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_five));
			// } else if ("26".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_two_six));
			// } else if ("31".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_one));
			// } else if ("32".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_two));
			// } else if ("33".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_three));
			// } else if ("34".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_four));
			// } else if ("35".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_five));
			// } else if ("36".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_three_six));
			// } else if ("41".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_one));
			// } else if ("42".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_two));
			// } else if ("43".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_three));
			// } else if ("44".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_four));
			// } else if ("45".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_five));
			// } else if ("46".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_four_six));
			// } else if ("51".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_one));
			// } else if ("52".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_two));
			// } else if ("53".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_three));
			// } else if ("54".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_four));
			// } else if ("55".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_five));
			// } else if ("56".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_five_six));
			// } else if ("61".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_one));
			// } else if ("62".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_two));
			// } else if ("63".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_three));
			// } else if ("64".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_four));
			// } else if ("65".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_five));
			// } else if ("66".equals(dataSourceListBlock.get(position).get(
			// "item_image"))) {
			// holder.item_image.setBackground(getResources().getDrawable(
			// R.color.palette_six_six));
			// }
			holder.item_text.setText(dataSourceListBlock.get(position).get(
					"item_text")
					+ "");

			return convertView;
		}

		private void setcolor(TextView aisle, int position,
				LinearLayout textViewLine) {
			if ("".equals(dataSourceListBlock.get(position).get("item_image"))) {
				aisle.setBackground(getResources().getDrawable(R.color.white));
				textViewLine.setVisibility(View.INVISIBLE);
			} else if ("11".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_one));
			} else if ("12".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_two));
			} else if ("13".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_three));
			} else if ("14".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_four));
			} else if ("15".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_five));
			} else if ("16".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_one_six));
			} else if ("21".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_one));
			} else if ("22".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_two));
			} else if ("23".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_three));
			} else if ("24".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_four));
			} else if ("25".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_five));
			} else if ("26".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_two_six));
			} else if ("31".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_one));
			} else if ("32".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_two));
			} else if ("33".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_three));
			} else if ("34".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_four));
			} else if ("35".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_five));
			} else if ("36".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_three_six));
			} else if ("41".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_one));
			} else if ("42".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_two));
			} else if ("43".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_three));
			} else if ("44".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_four));
			} else if ("45".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_five));
			} else if ("46".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_four_six));
			} else if ("51".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_one));
			} else if ("52".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_two));
			} else if ("53".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_three));
			} else if ("54".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_four));
			} else if ("55".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_five));
			} else if ("56".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_five_six));
			} else if ("61".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_one));
			} else if ("62".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_two));
			} else if ("63".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_three));
			} else if ("64".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_four));
			} else if ("65".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_five));
			} else if ("66".equals(dataSourceListBlock.get(position).get(
					"item_image"))) {
				aisle.setBackground(getResources().getDrawable(
						R.color.palette_six_six));
			} else if (dataSourceListBlock.get(position).get("item_image") == null) {
				aisle.setBackground(getResources().getDrawable(R.color.white));
				textViewLine.setVisibility(View.INVISIBLE);

			} else {
				aisle.setBackground(getResources().getDrawable(R.color.white));
				textViewLine.setVisibility(View.INVISIBLE);
			}

		}
	}

	public void initSimpleLineChartView() {
		// 上部分
		steptRv = BindView(R.id.steptRv);
		LayoutManager layoutManager = new GridLayoutManager(this, 1);
		((GridLayoutManager) layoutManager)
				.setOrientation(OrientationHelper.HORIZONTAL);
		steptRv.setLayoutManager(layoutManager);
		activityMethodBeans = new ArrayList<MethodBean>();
		activityMethodBeans
				.addAll(MethodsActivity1.getInstence().activityMethodBeans);
		recyclerViewAdapter = new RecyclerViewAdapter(activityMethodBeans);
		steptRv.setAdapter(recyclerViewAdapter);

		// 下部分
		mSimpleLineChart = BindView(R.id.simpleLineChart);
		pointMap = MethodsActivity1.getInstence().pointMap;
		pointMaps = MethodsActivity1.getInstence().pointMaps;

		mSimpleLineChart.setData(pointMap);
		mSimpleLineChart.setData2(pointMaps);
		mSimpleLineChart.setYItem(yItem);
		UpdateView();

	}

	public class RecyclerViewAdapter extends
			RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

		ArrayList<MethodBean> methodBeans = new ArrayList<MethodBean>();

		public RecyclerViewAdapter(ArrayList<MethodBean> methodBeans) {
			super();
			this.methodBeans = methodBeans;
		}

		class MyViewHolder extends ViewHolder {

			TextView titleTv;
			LinearLayout orline, line;
			ImageView exitBtn;

			public MyViewHolder(View view) {
				super(view);
				// temperatureTv = (TextView) view
				// .findViewById(R.id.temperatureTv);
				// timeTv = (TextView) view.findViewById(R.id.timeTv);
				// deltaTTv = (TextView) view.findViewById(R.id.deltaTTv);
				line = (LinearLayout) view.findViewById(R.id.line);
				titleTv = (TextView) view.findViewById(R.id.titleTv);
				orline = (LinearLayout) view.findViewById(R.id.orline);
				exitBtn = (ImageView) view.findViewById(R.id.exitBtn);
			}
		}

		@Override
		public int getItemCount() {
			return methodBeans.size() >= 0 ? methodBeans.size() : 0;
		}

		@Override
		public int getItemViewType(int position) {

			if (position == methodBeans.size()) {
				return 0;
			}

			if ("step".equals(methodBeans.get(position).getSteptType())) {
				return 1;
			} else if ("solubilityCurve".equals(methodBeans.get(position)
					.getSteptType())) {
				return 2;
			}

			return 0;

		}

		@Override
		public void onBindViewHolder(final MyViewHolder holder,
				final int position) {
			final int index = position + 1;
			if (getItemViewType(position) == 1) {
				// holder.temperatureTv.setText(methodBeans.get(position)
				// .getTemperature());
				// holder.timeTv.setText(methodBeans.get(position).getTime());

				holder.titleTv.setText("Step" + index);

			} else if (getItemViewType(position) == 2) {
				// holder.temperatureTv.setText(methodBeans.get(position)
				// .getTemperature());
				// holder.timeTv.setText(methodBeans.get(position).getTime());
				// holder.deltaTTv.setText(methodBeans.get(position).getDeltaT());
				holder.titleTv.setText("Step" + index);

			} else {

			}

		}

		@Override
		public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
			if (viewType == 1) {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						PreviewActivity.this).inflate(
						R.layout.item_methods_step_title, parent, false));
				return holder;
			} else if (viewType == 2) {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						PreviewActivity.this).inflate(
						R.layout.item_methods_step_title, parent, false));
				return holder;
			} else {
				MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
						PreviewActivity.this).inflate(
						R.layout.item_methods_step_create_new, parent, false));
				return holder;
			}
		}
	}

	private void UpdateView() {

		switch (pointMap.size()) {
		case 0:
			xItem = new String[] { "" };
			break;
		case 1:
			xItem = new String[] { "Step1" };
			break;
		case 2:
			xItem = new String[] { "Step1", "", };
			break;
		case 3:
			xItem = new String[] { "Step1", "", "Step2" };
			break;
		case 4:
			xItem = new String[] { "Step1", "", "Step2", "" };
			break;
		case 5:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3" };
			break;
		case 6:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "" };
			break;

		case 7:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4" };
			break;
		case 8:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "" };
			break;
		case 9:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5" };
			break;
		case 10:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "" };
			break;
		case 11:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6" };
			break;
		case 12:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "" };
			break;
		case 13:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7" };
			break;
		case 14:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "" };
			break;
		case 15:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "", "Step8" };
			break;
		case 16:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "" };
			break;
		case 17:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9" };
			break;
		case 18:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "" };
			break;
		case 19:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10" };
			break;
		case 20:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "" };
			break;
		case 21:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11" };
			break;
		case 22:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "" };
			break;
		case 23:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12" };
			break;
		case 24:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "" };
			break;
		case 25:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13" };
			break;
		case 26:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "" };
			break;
		case 27:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14" };
			break;
		case 28:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "" };
			break;
		case 29:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15" };
			break;
		case 30:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "" };
			break;
		case 31:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16" };
			break;
		case 32:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "" };
			break;
		case 33:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17" };
			break;
		case 34:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "" };
			break;
		case 35:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18" };
			break;
		case 36:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "" };
			break;
		case 37:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19" };
			break;
		case 38:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "" };
			break;
		case 39:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "",
					"Step20" };
			break;
		case 40:
			xItem = new String[] { "Step1", "", "Step2", "", "Step3", "",
					"Step4", "", "Step5", "", "Step6", "", "Step7", "",
					"Step8", "", "Step9", "", "Step10", "", "Step11", "",
					"Step12", "", "Step13", "", "Step14", "", "Step15", "",
					"Step16", "", "Step17", "", "Step18", "", "Step19", "",
					"Step20", "" };

			break;

		default:
			break;
		}
		mSimpleLineChart.setXItem(xItem);

		for (int i = 0; i < activityMethodBeans.size(); i++) {
			pointMaps.get(i).put("temperature",
					activityMethodBeans.get(i).getTemperature());
			pointMaps.get(i).put("time", activityMethodBeans.get(i).getTime());
			pointMaps.get(i).put("deltaT",
					activityMethodBeans.get(i).getDeltaT());
			pointMaps.get(i).put("gotTo", activityMethodBeans.get(i).getGoTo());
			pointMaps.get(i).put("repititions",
					activityMethodBeans.get(i).getRepititions());

		}

		mSimpleLineChart.setData(pointMap);
		mSimpleLineChart.setData2(pointMaps);
	}

	@Override
	public void onScrollChanged(MyHorizontalScrollView scrollView, int x,
			int y, int oldx, int oldy) {

		if (scrollView == downScrollView) {

			upScrollView.smoothScrollTo(x, 0);

		}
		if (scrollView == upScrollView) {
			downScrollView.smoothScrollTo(x, 0);

		}

	}
}
